package Service.impl;

import View.Database;
import Entity.AdminDo;
import Service.Admin;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Admi implements Admin{
    public boolean validateAdmin(AdminDo adminDo){
        String userName=adminDo.getUserName() ;
        String pwd1 = adminDo.getPwd();
        String sql="select pwd from manage where user_name=?";
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet resultSet=null;
        try {
             conn= Database.getConn();
             if (conn==null){
                 return false;
             }
             ps=conn.prepareStatement(sql);
             ps.setString(1,adminDo.getUserName());
             resultSet=ps.executeQuery() ;
             while (resultSet.next()){
                String pwd= resultSet.getString(1);
                if (pwd1.equals(pwd)){
                    return true;
                }
             }
        }catch (Exception e){

        }finally {

            Database.closePs(ps);
            Database.closeRs(resultSet);
            Database.closeConn(conn);

        }


        return false;
    }
}
